Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

fix: support <thought> tag rendering for Gemma 4 reasoning - #12096

Draft
ghost wants to merge 1 commit into
mainfrom
fix/thought-tag-rendering
Draft

fix: support <thought> tag rendering for Gemma 4 reasoning#12096
ghost wants to merge 1 commit into
mainfrom
fix/thought-tag-rendering

Conversation

@ghost

@ghost ghost commented Apr 10, 2026

Copy link
Copy Markdown

This PR attempts to address Issue #12093.

Problem

Gemma 4 31B outputs its reasoning process with <thought>...</thought> tags, but Roo Code only recognized <think>...</think> tags for reasoning extraction. This caused the raw <thought> tags to appear in the chat UI instead of being rendered as reasoning content.

Changes

  1. src/utils/tag-matcher.ts - Updated TagMatcher to accept string | string[] for tag names, enabling multi-tag matching during streaming. When multiple tag names are provided, the matcher tracks candidate matches character-by-character and ensures close tags match their corresponding open tags.

  2. Provider updates (4 files) - Updated all TagMatcher instantiation sites to recognize both "think" and "thought" tags:

    • src/api/providers/openai.ts
    • src/api/providers/base-openai-compatible-provider.ts
    • src/api/providers/lm-studio.ts
    • src/api/providers/native-ollama.ts
  3. src/core/assistant-message/presentAssistantMessage.ts - Added stripping of <thought> / </thought> tags alongside the existing <thinking> tag stripping.

  4. src/utils/__tests__/tag-matcher.spec.ts - Added 13 tests covering single tag, multi-tag, streaming, mismatched tag, and transform scenarios.

Testing

  • All 13 new TagMatcher tests pass
  • All 13 existing base-openai-compatible-provider tests pass
  • Full lint and type-check pass across the monorepo

Feedback and guidance are welcome.

Interactively review PR in Roo Code Cloud

Gemma 4 31B uses <thought>...</thought> tags for its reasoning process,
but Roo Code only recognized <think>...</think> tags. This change:

- Updates TagMatcher to accept multiple tag names (string | string[])
- Adds "thought" as an additional recognized reasoning tag in all 4
  providers (openai, base-openai-compatible, lm-studio, native-ollama)
- Strips <thought> tags in presentAssistantMessage alongside <thinking>
- Adds comprehensive test coverage for multi-tag matching

Fixes #12093
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant